﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;

/** 
 ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
 * Description: 
 * Author: Heller (HellerSong@outlook.com)
 * CreationTime: 3/28/2015 7:23:52 PM
 ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** 
 **/
namespace DevGrammar.TestBasic
{
	[TestClass]
	public class TestDictionary
	{
		[TestMethod]
		public void test_init_and_show_dict()
		{
			Dictionary<string, int> dict = new Dictionary<string, int>()
	        {
	            {"cat", 2},
	            {"dog", 1},
	            {"llama", 0},
	            {"iguana", -1}
	        };
			// Show dictionary data
			foreach (var pair in dict)
				Console.WriteLine(pair.Key + ": " + pair.Value);
			Console.WriteLine();
		}

		[TestMethod]
		public void test_dict_operaction()
		{
			Dictionary<string, string> dict = new Dictionary<string, string>();

			//Add
			dict.Add("XLCaseID", "3345");
			dict.Add("XLFileName", "wordRibbonHomeFontPalatinoMoreInfo");

			//Delete
			dict.Remove("XLCaseID"); // Removes XLCaseID
			dict.Remove("nothing"); // Doesn't remove anything

			//Update
			dict["XLCaseID"] = "3348";

			// Search
			if (dict.ContainsKey("apple"))
			{
				string value = dict["apple"];
				Console.WriteLine("The value of search key 'apple' is: " + value);
			}

			//Show1
			Console.WriteLine("Dictionary Count is: " + dict.Count);
			Console.WriteLine("XL Case ID is: " + dict["XLCaseID"]);
			Console.WriteLine("XL File Name is: " + dict["XLFileName"]);
			foreach (var pair in dict)
				Console.WriteLine("{0}, {1}", pair.Key, pair.Value);
			Console.WriteLine();

			//Show2 using Key property
			List<string> keyList = new List<string>(dict.Keys);
			foreach (string k in keyList)  // Loop through list
				Console.WriteLine("{0}, {1}", k, dict[k]);
		}


	}
}
